﻿@model BlogPostListModel
@using SmartStore.Web.Models.Blogs;
@using SmartStore.Web.Framework.UI;
@using System.Globalization;

@{
    Layout = "_Layout";
    
    var parsedMonth = Model.PagingFilteringContext.GetParsedMonth();

    Html.AddTitleParts(
        parsedMonth != null ?
        T("PageTitle.Blog.Month").Text.FormatWith(parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year) :
        T("PageTitle.Blog.Tag").Text.FormatWith(Model.PagingFilteringContext.Tag)
    );
    Html.AddMetaDescriptionParts(
        parsedMonth != null ?
        T("Metadesc.Blog.Month").Text.FormatWith(parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year) :
        T("Metadesc.Blog.Tag").Text.FormatWith(Model.PagingFilteringContext.Tag)
    );
}

@section right {
    @{
        Html.RenderAction("BlogMonths", "Blog");
        Html.RenderAction("BlogTags", "Blog");

        <div class="d-none d-lg-block">
            @{ Html.RenderAction("PollBlock", "Poll", new { systemKeyword = "Blog" }); }
        </div>
    }
}

<div class="page blog-page">
    <div class="page-title row">
        <div class="col">
            <div class="heading">
                <h1 class="heading-title">
                    @if (String.IsNullOrEmpty(Model.PagingFilteringContext.Tag))
					{
						if (Model.PagingFilteringContext.GetParsedMonth().HasValue)
						{
							@T("Blog.FilteredByMonth", Model.PagingFilteringContext.GetParsedMonth().Value.Year, Model.PagingFilteringContext.GetParsedMonth().Value.ToNativeString("MMMM"))
						}
						else
						{
                            @T("Blog")
						}
					}
					else
					{
						@T("Blog.TaggedWith", Model.PagingFilteringContext.Tag)
					}
                </h1>
            </div>
        </div>
        <div class="col col-auto text-right">
            <a class="btn btn-warning" href="@Url.RouteUrl("BlogRSS", new { languageId = Model.WorkingLanguageId })" title="@T("Blog.RSS.Hint")">
                <i class="fa fa-rss"></i>
                <span>@T("Blog.RSS")</span>
            </a>
        </div>
    </div>

    <div class="page-body">
        
        @{ Html.RenderWidget("bloglist_page_before_posts"); }

        <div class="blogposts">
            @foreach (var item in Model.BlogPosts)
            {
                <article class="blogpost row mt-0">
                    
                    <div class="blogpost-content col-12 col-md-9">
                        <h3 class="blogpost-title">
                            <a href="@Url.RouteUrl("BlogPost", new { SeName = item.SeName })">
                                @item.Title
                            </a>
                        </h3>

                        <div class="blogpost-body html-editor-content">
                            @Html.Raw(item.Body)
                        </div>

                        @{ Html.RenderWidget("bloglist_page_inside_post"); }
                    </div>

                    <div class="blogpost-info col-12 col-md-3">
                        @if (item.Comments.AllowComments)
                        {
                            <a class="blogpost-comments@(item.Comments.NumberOfComments > 0 ? " vivid" : "") d-none d-md-block"
                               href="@Url.RouteUrl("BlogPost", new { SeName = item.SeName })"
                               title="@string.Format(@T("Blog.CommentsLink").Text, item.Comments.NumberOfComments)"
                               data-toggle="tooltip">
                                <span class="blogpost-comments-icon fa fa-comments"></span>
                                <span class="blogpost-comments-count">@item.Comments.NumberOfComments</span>
                            </a>
                        }

                        <div class="blogpost-date mb-2 text-muted">
                            @item.CreatedOn.ToNativeString("dd MMMM, yyyy")
                        </div>

                        @if (item.Tags.Count > 0)
                        {
                            <div class="blogpost-tags mb-3 mb-md-0 p-2">
                                <i class="fa fa-tags" title='@T("Blog.Tags")'></i>
                                @for (int i = 0, length = item.Tags.Count; i < length; i++)
                                {
                                    var tag = item.Tags[i];
                                    var isLast = i == length - 1;
                                    <a class="blogpost-tag" href="@Url.RouteUrl("BlogByTag", new { tag = tag.SeName })">@tag.Name@(!isLast ? "," : "")</a>
                                }
                            </div>
                        }
                    </div>

                </article>
            }
        </div>

        @(Html.SmartStore().Pager(Model.PagingFilteringContext)
				.Name("pagination-bottom")
				.QueryParam("pagenumber")
				.ShowFirst(false)
				.ShowLast(false)
				.Style(PagerStyle.Pagination)
				.MaxPagesToDisplay(6))

        @{ Html.RenderWidget("bloglist_page_after_posts"); }
    </div>
</div>
